
#include "draw.h"



void scrolling (SDL_Surface *image , int x )
{
        SDL_Rect dest , src ;

        dest.x = 0;
       	dest.y = 0;
       	dest.w = SCREEN_WIDTH;
       	dest.h = SCREEN_HEIGHT;

		src.x = x;
       	src.y = 0;
       	src.w = SCREEN_WIDTH;
       	src.h = SCREEN_HEIGHT;

		SDL_BlitSurface(image,&src,jeu.screen,&dest);
		SDL_Delay(1);
}

void blite_obstacle (SDL_Surface *image )
{
        SDL_Rect dest ;

        dest.x = obs.x[0];
       	dest.y = obs.y[0];

		SDL_BlitSurface(image,NULL,jeu.screen,&dest);

}

void blite (SDL_Surface *image)
{
        SDL_Rect dest ;

        dest.x = 0 ;
       	dest.y = 0 ;

		SDL_BlitSurface(image,NULL,jeu.screen,&dest);
}

void draw(void)
{
    scrolling(map.background[0],map.x[0]);
    scrolling(map.background[1],map.x[1]);
    scrolling(map.background[2],map.x[2]);



    drawanimatedplayer ();
   /* if ( map.x[0] > 1000  )
    blite_obstacle( obs.obstacle[0] ); */

    SDL_Flip(jeu.screen);
}


SDL_Surface *loadImage(char *name)
{
	SDL_Surface *temp = IMG_Load(name);
	SDL_Surface *image;

	if (temp == NULL)
	{
		printf("Failed to load image %s\n", name);
		return NULL;
	}


       SDL_SetColorKey(temp, (SDL_SRCCOLORKEY | SDL_RLEACCEL), SDL_MapRGB(temp->format,
                                                   255, 255 , 255));

	image = SDL_DisplayFormat(temp);
	//image =  SDL_DisplayFormatAlpha (temp);
	SDL_FreeSurface(temp);

	if (image == NULL)
	{
		printf("Failed to convert image %s to native format\n", name);
		return NULL;
	}
	return image ;
}


